<?php
class Maps extends BlockInstance {
	function __call($m, $a)
	{
		global $BBX;
		
		$CI =& get_instance();
		
		if (preg_match('/[a-z]+_([a-z]+)/', $m, $matches))
		{
			$bounds = false;
			if ($matches[1] == 'homepage')
			{
				// find lat/lng bounds
				$query = $CI->db->query('select min(geo_lat) as min_lat,max(geo_lat) as max_lat,min(geo_lon) as min_lon,max(geo_lon) as max_lon
					from contents
					where bricabox_id = ?', array($BBX['bricabox']->id));
				foreach(array('max_lat', 'max_lon', 'min_lat', 'min_lon') as $attr)
					$bounds[$attr] = $query->first_row()->$attr ? $query->first_row()->$attr : 0;
			}
			$CI->load->view('blocks/maps/'.$matches[1], array('bounds' => $bounds, 'block_instance' => $a[0]));
		}
	}
}
?>